<?php

    /* cookie management class */
    class CCookie
    {	
		 //get class instance
		 static function &GetInstance()
		 {
			global $g_hObjects;
			static $m_hApp = NULL;
						 
			if(!isset($m_hApp))
			{
				$m_hApp = new CCookie();					 
				$g_hObjects[] = $m_hApp;
				$m_hApp->OnInit();
			}
			
			return $m_hApp;
		}
		
		function OnInit()
		{	
		}
		
		function OnDestroy()
		{
		}
		
		
		//add cookie
		function Set($szName,$szVal,$iTime = '')
		{
			$szName = strip_tags($szName);
			
			$szVal = substr($szVal,0,intval(COOKIE_MAX_LEN));
			$szVal = trim($szVal);		//stripping whitespaces
			$szVal = urlencode($szVal); 	//for ex. http://onet.pl/?test=jakos&cos=ktos will pass by
			$szVal = strip_tags($szVal);
			
			//$iTime = ($iTime == '') ? mktime(0,0,0,date("m"),date("d"),date("Y")+10) : time() + $iTime;
			
			$iTime = mktime(0,0,0,date("m"),date("d"),date("Y")+10);
			
			if(setcookie($szName,$szVal,$iTime,'/','',false) == FALSE)
			{
				SetError("Unable to set cookie: $szName=>$szVal",true);
				return false;
			}
			
			return true;
		}
		
		//delete cookie
		function Delete($szName)
		{
			setcookie($szName,"",time()-3600);
		}
		
		//get cookie
		function Get($szName,$iLen = COOKIE_MAX_LEN)
		{
			$szVal = '';
			
			if(isset($_COOKIE[$szName]))
			{
				$szVal = substr($_COOKIE[$szName],0,$iLen);
				$szVal = trim($szVal);
				$szVal = urldecode($szVal); //for ex. http://onet.pl/?test=cos&grzyb=ktos will pass by
				$szVal = strip_tags($szVal);
			
				return $szVal;
			}
			
			return '';
		}
    }
    
?>